<%#
 Copyright 2013-2025 the original author or authors from the JHipster project.

 This file is part of the JHipster project, see https://www.jhipster.tech/
 for more information.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      https://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-%>
<div class="modal-header">
  <h4 class="modal-title">__jhiTranslateTag__('metrics.jvm.threads.dump.title')</h4>

  <button type="button" class="btn-close" (click)="dismiss()">&nbsp;</button>
</div>

<div class="modal-body">
  <div class="mb-3">
    <button class="badge bg-primary hand" (click)="threadStateFilter = undefined" (keydown.enter)="threadStateFilter = undefined">
      @if (threadStateFilter === undefined) {
        <fa-icon icon="check" />
      }
      All&nbsp;<span class="badge rounded-pill bg-default">{{ threadDumpAll }}</span>
    </button>

    <button
      class="badge bg-success hand"
      (click)="threadStateFilter = ThreadState.Runnable"
      (keydown.enter)="threadStateFilter = ThreadState.Runnable"
    >
      @if (threadStateFilter === ThreadState.Runnable) {
        <fa-icon icon="check" />
      }
      Runnable&nbsp;<span class="badge rounded-pill bg-default">{{ threadDumpRunnable }}</span>
    </button>

    <button
      class="badge bg-info hand"
      (click)="threadStateFilter = ThreadState.Waiting"
      (keydown.enter)="threadStateFilter = ThreadState.Waiting"
    >
      @if (threadStateFilter === ThreadState.Waiting) {
        <fa-icon icon="check" />
      }
      Waiting&nbsp;<span class="badge rounded-pill bg-default">{{ threadDumpWaiting }}</span>
    </button>

    <button
      class="badge bg-warning hand"
      (click)="threadStateFilter = ThreadState.TimedWaiting"
      (keydown.enter)="threadStateFilter = ThreadState.TimedWaiting"
    >
      @if (threadStateFilter === ThreadState.TimedWaiting) {
        <fa-icon icon="check" />
      }
      Timed Waiting&nbsp;<span class="badge rounded-pill bg-default">{{ threadDumpTimedWaiting }}</span>
    </button>

    <button
      class="badge bg-danger hand"
      (click)="threadStateFilter = ThreadState.Blocked"
      (keydown.enter)="threadStateFilter = ThreadState.Blocked"
    >
      @if (threadStateFilter === ThreadState.Blocked) {
        <fa-icon icon="check" />
      }
      Blocked&nbsp;<span class="badge rounded-pill bg-default">{{ threadDumpBlocked }}</span>
    </button>
  </div>

  @for (thread of getThreads(); track $index) {
    <div class="pad">
      <h6>
        <span class="badge" [ngClass]="getBadgeClass(thread.threadState)">{{ thread.threadState }}</span>

        &nbsp;{{ thread.threadName }} (ID {{ thread.threadId }})

        <a (click)="thread.showThreadDump = !thread.showThreadDump" href="javascript:void(0);">
          <span [hidden]="thread.showThreadDump">__jhiTranslateTag__('metrics.jvm.threads.dump.show')</span>
          <span [hidden]="!thread.showThreadDump">__jhiTranslateTag__('metrics.jvm.threads.dump.hide')</span>
        </a>
      </h6>

      <div class="card" [hidden]="!thread.showThreadDump">
        <div class="card-body">
          @for (st of thread.stackTrace; track $index) {
            <div class="break">
              <samp
                >{{ st.className }}.{{ st.methodName }}(<code>{{ st.fileName }}:{{ st.lineNumber }}</code
                >)</samp
              >
              <span class="mt-1"></span>
            </div>
          }
        </div>
      </div>
      <table class="table table-sm table-responsive">
        <caption>
          Threads dump:
          {{
            thread.threadName
          }}
        </caption>
        <thead>
          <tr>
            <th scope="col">__jhiTranslateTag__('metrics.jvm.threads.dump.blockedtime')</th>
            <th scope="col">__jhiTranslateTag__('metrics.jvm.threads.dump.blockedcount')</th>
            <th scope="col">__jhiTranslateTag__('metrics.jvm.threads.dump.waitedtime')</th>
            <th scope="col">__jhiTranslateTag__('metrics.jvm.threads.dump.waitedcount')</th>
            <th scope="col">__jhiTranslateTag__('metrics.jvm.threads.dump.lockname')</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>{{ thread.blockedTime }}</td>
            <td>{{ thread.blockedCount }}</td>
            <td>{{ thread.waitedTime }}</td>
            <td>{{ thread.waitedCount }}</td>
            <td class="thread-dump-modal-lock" title="{{ thread.lockName }}">
              <code>{{ thread.lockName }}</code>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
  }
</div>
<div class="modal-footer">
  <button type="button" class="btn btn-secondary float-start" data-dismiss="modal" (click)="dismiss()">Done</button>
</div>
